package com.heima.controller;
import com.heima.common.PageResult;
import com.heima.pojo.VmType;
import com.heima.pojo.dto.VmTypeDto;
import com.heima.service.VmTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/vmType")
@Slf4j
@RequiredArgsConstructor
public class VmTypeController {

    private final VmTypeService vmTypeService;

    @GetMapping("/{typeId}")
    public VmType getVmType(@PathVariable Integer typeId) {
        return vmTypeService.getById(typeId);
    }
    /**
     * 查询设备类型
     * @param vmTypeDto
     * @return
     */
    @GetMapping("/search")
    public PageResult<VmType> searchVmType(VmTypeDto vmTypeDto) {
        log.info("查询所有设备类型");
        return vmTypeService.searchVmType(vmTypeDto);
    }

    /**
     * 保存设备类型
     * @param vmType
     * @return
     */
    @PostMapping
    public Boolean saveVmType(@RequestBody VmType vmType) {
        log.info("保存设备类型");
        return vmTypeService.saveVmType(vmType);
    }

    /**
     * 修改设备类型
     * @param vmType
     * @return
     */
    @PutMapping("/{id}")
    public Boolean updateVmType(@RequestBody VmType vmType) {
        log.info("修改设备类型信息");
        return vmTypeService.updateVmType(vmType);
    }

    /**
     * 删除设备类型
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Boolean deleteVmType(@PathVariable Integer id) {
        log.info("删除设备类型信息");
        return vmTypeService.removeVmType(id);
    }
}
